package icu.guodapeng.oauth2.exception

import icu.guodapeng.oauth2.api.CommonResult
import org.springframework.security.oauth2.common.exceptions.OAuth2Exception
import org.springframework.web.bind.annotation.ControllerAdvice
import org.springframework.web.bind.annotation.ExceptionHandler
import org.springframework.web.bind.annotation.ResponseBody


/**
 * 全局处理 Oauth2 抛出的异常
 */
@ControllerAdvice
class Oauth2ExceptionHandler {
    @ResponseBody
    @ExceptionHandler(value = [OAuth2Exception::class])
    fun handleOauth2(e: OAuth2Exception): CommonResult<Any?> =
        if (e.message is String) CommonResult.failed(e.message!!) else CommonResult.failed()
}
